<template>
	<view class="wrap">
		<view class="tabs-list">
			<u-tabs :list="tablist" :is-scroll="false" height="100" :bold="false" font-size="30" bar-height="2" bar-width="365" :current="current" @change="tabchange"></u-tabs>
		</view>
		<view class="search">
			<u-search height="70" color="#B9B9B9" bg-color="#F0F0F0" margin="15rpx 40rpx 30rpx" search-icon-color="#B9B9B9" placeholder-color="#B9B9B9" placeholder="请输入您所查询的老师" v-model="keyword" @search="search" :show-action="false"></u-search>
			<view class="search-con">
				<view class="search-con-l">
					<u-checkbox size="30" @change="quanxuan" v-model="allChecked" name="全选"  shape="circle">全选</u-checkbox>
				</view>
				<view class="search-con-r" @click="gomuban">
					新建收费模板
				</view>
			</view>
		</view>
		<!-- 列表 -->
		<view class="school-body">
			<!-- 定价 -->
			<view class="school-list" v-if="current == 0" v-for="(item,index) in schoolList" :key="item.id">
				<view class="school">
					<view class="school-l">
						<u-checkbox @change="danxuan"  v-model="item.checked" :name="index" size="30" shape="circle"><text class="school-name">{{item.bumen}}</text></u-checkbox> 
					</view>
					<view class="school-r">
						月收费：{{item.feemoban.mounth_fee}}元
					</view>
				</view>
				<view class="can" >
					<view class="can-l" >
						<view class="can-li" >
							<view class="can-li-kuang">
							</view>
							<view class="can-li-title">
								午餐
							</view>
							<view class="can-li-price">
								{{item.feemoban.lunch_fee}}元
							</view>
						</view>
						<view class="can-li" >
							<view class="can-li-kuang">
							</view>
							<view class="can-li-title">
								晚餐
							</view>
							<view class="can-li-price">
								{{item.feemoban.dinner_fee}}元
							</view>
						</view>
					</view>
					<view class="can-r">
						更改定价
					</view>
				</view>
			</view>	
			<!-- 未定价 -->
			<view class="school-list" v-if="current == 1" v-for="(item,index) in schoolListwei" :key="item.id">
				<view class="school">
					<view class="school-l">
						<u-checkbox @change="danxuan"   v-model="item.checked" :name="index" size="30"  shape="circle"><text class="school-name">{{item.bumen}}</text></u-checkbox> 
					</view>
					<view class="school-r">
						月收费
					</view>
				</view>
				<view class="can" >
					<view class="can-l" >
						<view class="can-li" >
							<view class="can-li-kuang">
							</view>
							<view class="can-li-title">
								午餐
							</view>
							
						</view>
						<view class="can-li" >
							<view class="can-li-kuang">
							</view>
							<view class="can-li-title">
								晚餐
							</view>
						</view>
					</view>
					<view class="can-r">
						设置定价
					</view>
				</view>
			</view>	
		</view>
		<!-- 模板 -->
		<view class="chooise">
			<text class="chooise-text">选择模板</text>
			 <easy-select inputStyle="color:#333333;font-size:28rpx;" placeholderStyle="color:#333333;font-size:28rpx;"  @selectOne="selectOne" ref="easySelect" size="small" style="font-size: 25rpx; border-radius:0;width: 385rpx;height: 56rpx;color: #333333;background-color: #fff;" :value="selecValue" :options="tempoptions"></easy-select>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				keyword:"", // 搜索关键字
				tablist: [{
						name: '已定价'
					  }, {
						name: '未定价'
					  }],
				 schoolListwei:[], //未定价
				 schoolList:[], //已定价	   
				 current: 0,
				 allChecked:false,
				 selecValue: '',
				 tempoptions:[],
            }	
		},
		onLoad() {
			this.feemobanList();
            this.schoolListjk(1)
			this.schoolListjk(2)
		},
		// computed: {
		// },
		methods: {
			gomuban(){
				this.$u.route('/pages/finance/muban')
			},
			danxuan(e){
				console.log(e)
				let current = this.current
				if(current == 0){
					this.schoolList[e.name].checked = e.value
					
				}else{
					this.schoolListwei[e.name].checked = e.value
				}
				  this.$forceUpdate()
			},
			//全选
			quanxuan(e){
				let current = this.current
				if(current == 0){
					this.schoolList.map(val => {
						val.checked = e.value
					})
				}else{
					this.schoolListwei.map(val => {
						val.checked = e.value
					})
					console.log(this.schoolListwei);
				}
			},
			//搜索
			search(){
				let current = this.current
				if(current == 0){
					 this.schoolListjk(1)
				}else{
					this.schoolListjk(2)
				}
			},
			//列表
			schoolListjk(index){
				let form = {
					"school_name":this.keyword,
					"is_feemobanid": index
				};	
				this.$u.post('api/school/schoolFeeMobanlist', form).then(res => {
						if(index == 1){
							this.schoolList = res
						}else{
							this.schoolListwei = res //未定价
						}
				})
			},
			//模板列表
			feemobanList(){
				this.$u.post('api/school/feemobanList').then(res => {
					this.tempoptions = res
				})
			},
			tabchange(index){
				this.current = index;
			},
			selectOne(options){
				this.selecValue = options.label
				let feemoban_id = options.value
				
				let current = this.current
				let school_ids = [];
				if(current == 0){
					this.schoolList.forEach(val => {
						if(val.checked){
							school_ids.push(val.id);
						}
					})
				}else{
					this.schoolListwei.forEach(val => {
						if(val.checked){
							school_ids.push(val.id);
						}
					})
				}
				if(school_ids.length == 0){
					this.$u.toast("请选择学校")
					return;
				}
				this.$u.post('api/school/schoolbumenmobanupdate', {
					feemoban_id:feemoban_id,
					school_ids:school_ids
				}).then(res => {
						 this.$u.toast("成功")
						 this.schoolListjk(1)
						 this.schoolListjk(2)
				})
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	page{
		background-color: #F8F8F7;
	}
	
	.wrap {
		display: flex;
		flex-direction: column;
		height: calc(100vh - var(--window-top));
		width: 100%;
	
	}
	
	.search{
		margin-top: 20rpx;
		margin-bottom: 10rpx;
		background-color: #fff;
		height:200rpx;
		//overflow: hidden;
		//flex:1;
		.search-con{
			display: flex;
			justify-content: space-between;
			padding: 0 40rpx;
			align-items: center;
			.search-con-r{
				line-height: 48rpx;
				background: #2165F7;
				border-radius: 4rpx;
				text-align: center;
				color: #fff;
				font-size: 24rpx;
				width: 172rpx;
			}
		}
	}

   .school-body{
	   flex: 1;
	   overflow-y: scroll;
   }
	.school-list{
		background-color: #fff;
		margin-bottom: 20rpx;
		overflow: hidden;
		.school{
			display: flex;
			justify-content: space-between;
			margin: 0 40rpx;
			height: 90rpx;
			align-items: center;
			border-bottom: 2rpx solid #F1F1F1;
			.school-l{
				
				.school-title{
					font-size: 30rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #333333;
					padding-left:20rpx;
				}
			}
			.school-r{
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #D53030;
			}
		}
		.can{
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding-right:40rpx;
			padding-left: 88rpx;
			padding-top: 32rpx;
			padding-bottom: 5rpx;
			.can-li{
				display: flex;
				align-items: center;
				margin-bottom: 20rpx;
				.can-li-kuang{
					width: 12rpx;
					height: 12rpx;
					background: #2165F7;
					border-radius: 2rpx;
				}
				.can-li-title{
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #999999;
					padding: 0 9rpx 0 8rpx;
				}
				.can-li-price{
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #333333;
				}
			}
			.can-r{
				width: 140rpx;
				height: 50rpx;
				line-height: 50rpx;
				background: #E89C38;
				border-radius: 25rpx;
				color: #fff;
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #F7F7F6;
				text-align: center;
			}
		}
	}
	
	// 模板选择
	.chooise{
		position: fixed;
		bottom: 20rpx;
		margin-left: -45%;
		left: 50%;
		width: 90%;
		height: 85rpx;
		background: #2165F7;
		border-radius: 20rpx;
	    color: #fff;
		display: flex;
		align-items: center;
		justify-content: center;
		
		.chooise-text{
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #FEFEFE;
			padding-right: 50rpx;
		}
	}

</style>
